/**
 * jims
 */
package com.jims.master.modules.drug.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.drug.entity.DrugInoutClass;
import com.jims.master.modules.drug.service.DrugInoutClassService;

import java.util.List;

/**
 * Controller
 * @author DT
 * @version 2017-03-06
 */
@Controller
@RequestMapping(value = "${adminPath}/drug/drugInoutClass")
public class DrugInoutClassController extends BaseController {

	@Autowired
	private DrugInoutClassService drugInoutClassService;
	
	@ModelAttribute
	public DrugInoutClass get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return drugInoutClassService.get(id);
		}
		else {
			return new DrugInoutClass();
		}
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(DrugInoutClass drugInoutClass, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DrugInoutClass> page = drugInoutClassService.findPage(new Page<DrugInoutClass>(request, response), drugInoutClass);
		model.addAttribute("page", page);
		return "modules/drug/drugInoutClassIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(DrugInoutClass drugInoutClass, Model model) {
		model.addAttribute("drugInoutClass", drugInoutClass);
		return "modules/drug/drugInoutClassForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(DrugInoutClass drugInoutClass, Model model) {
	    StringData data=new StringData();
		int i=drugInoutClassService.save(drugInoutClass);
        if(i>0){
            data.setCode("success");
            data.setData("保存成功");
        }else{
            data.setCode("error");
            data.setData("保存失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(DrugInoutClass drugInoutClass) {
	    StringData data=new StringData();
		int i=drugInoutClassService.delete(drugInoutClass);
        if(i>0){
            data.setCode("success");
            data.setData("删除成功");
        }else{
            data.setCode("error");
            data.setData("删除失败");
        }
		return data;
	}

}